package close.mazegame.screens;

import com.badlogic.gdx.Gdx;

import close.mazegame.input.uiinput.UIInput.UIKeys;
import close.mazegame.screens.MenuScreen;
import close.mazegame.InputHandler;
import close.mazegame.MazeGame;
import close.mazegame.screens.GameScreen;

public class PauseScreen extends Screen {
	
	private final GameScreen parent;
	private int select = 0;
	private String[] menuItems = { "RESUME", "RETURN TO MENU", "EXIT GAME"};

	public PauseScreen(GameScreen parent){
		this.parent = parent;
	}
	
	@Override
	public void render() {
		parent.render();
		
		spriteBatch.begin();

		for (int i = 0; i < menuItems.length; i++) {
			if (i == select) {
				drawString("- " + menuItems[i], MazeGame.WIDTH / 2, MazeGame.HEIGHT / 2 - (i * 24), 2);
			} else {
				drawString(menuItems[i], MazeGame.WIDTH / 2, MazeGame.HEIGHT / 2 - (i * 24), 2);
			}
		}
		spriteBatch.end();
	}

	@Override
	public void update(float delta) {
		if(InputHandler.uiInput.isTyped(UIKeys.UI_UP)){
			select--;
		}
		if(InputHandler.uiInput.isTyped(UIKeys.UI_DOWN)){
			select++;
		}
		while(select < 0){
			select += menuItems.length;
		}
		select = select%menuItems.length;
		
		if(InputHandler.uiInput.isTyped(UIKeys.UI_ENTER)){
			if(select == 0){
				setScreen(parent);
			} else if(select == 1){
				parent.dispose();
				setScreen(new MenuScreen());
			} else if(select == 2){
				Gdx.app.exit();
			}
		}
		
		if(InputHandler.uiInput.isTyped(UIKeys.UI_ESCAPE)){
			setScreen(parent);
			return;
		}

	}

	@Override
	public boolean isOverlay() {
		return true;
	}

}
